home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / include / tkText.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-16  |  15.6 KB  |  414 lines

  1. /*
  2.  * tkText.h --
  3.  *
  4.  *    Declarations shared among the files that implement text
  5.  *    widgets.
  6.  *
  7.  * Copyright 1992 Regents of the University of California.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  *
  16.  * $Header: /user6/ouster/wish/RCS/tkText.h,v 1.13 92/07/31 13:43:26 ouster Exp $ SPRITE (Berkeley)
  17.  */
  18.  
  19. #ifndef _TKTEXT
  20. #define _TKTEXT
  21.  
  22. #ifndef _TK
  23. #include "tk.h"
  24. #endif
  25.  
  26. /*
  27.  * Opaque types for structures whose guts are only needed by a single
  28.  * file:
  29.  */
  30.  
  31. typedef struct TkTextBTree *TkTextBTree;
  32.  
  33. /*
  34.  * The data structure below defines a single line of text (from newline
  35.  * to newline, not necessarily what appears on one line of the screen).
  36.  */
  37.  
  38. typedef struct TkTextLine {
  39.     struct Node *parentPtr;        /* Pointer to parent node containing
  40.                      * line. */
  41.     struct TkTextLine *nextPtr;        /* Next in linked list of lines with
  42.                      * same parent node in B-tree.  NULL
  43.                      * means end of list. */
  44.     struct TkAnnotation *annotPtr;    /* First in list of annotations for
  45.                      * this line. */
  46.     int numBytes;            /* Number of  bytes in line, including
  47.                      * newline but not terminating NULL. */
  48.     char bytes[4];            /* Contents of line, null-terminated.
  49.                      * The actual length of the array will
  50.                      * be as large as needed to hold the
  51.                      * line.  THIS MUST BE THE LAST FIELD
  52.                      * OF THE STRUCT. */
  53. } TkTextLine;
  54.  
  55. /*
  56.  * The structures below are used to describe annotations to the text
  57.  * (such as marks and embedded windows).  Annotations are placed at
  58.  * a given place in the text and then float to keep their position
  59.  * as text is inserted and deleted.  Each actual annotation
  60.  * contains a standard set of fields, plus a type-specific set of
  61.  * fields.  The types are as follows:
  62.  *
  63.  * TK_ANNOT_TOGGLE -    Marks the beginning or end of a range of
  64.  *            characters that have a given tag.
  65.  * TK_ANNOT_MARK -    Holds information about a given "mark" (see
  66.  *            user doc. for information on marks).
  67.  * TK_ANNOT_WINDOW -    Holds information on a window embedded in the
  68.  *            text.  Not implemented yet.
  69.  */
  70.  
  71. typedef enum {TK_ANNOT_TOGGLE, TK_ANNOT_MARK, TK_ANNOT_WINDOW} TkAnnotType;
  72.  
  73. typedef struct TkAnnotation {
  74.     TkAnnotType type;            /* Type of annotation. */
  75.     TkTextLine *linePtr;        /* Pointer to line structure
  76.                      * containing this annotation. */
  77.     int ch;                /* Index of character that annotation
  78.                      * is attached to (annotation is
  79.                      * considered to be just before this
  80.                      * character). */
  81.     struct TkAnnotation *nextPtr;    /* Next in list of annotations for
  82.                      * same line of text, or NULL if
  83.                      * end of list. */
  84.     union {                /* Type-specific information. */
  85.     struct TkTextTag *tagPtr;    /* Type == TK_ANNOT_TOGGLE. */
  86.     Tcl_HashEntry *hPtr;        /* Type == TK_ANNOT_MARK. */
  87.     } info;
  88. } TkAnnotation;
  89.  
  90. /*
  91.  * One data structure of the following type is used for each tag that
  92.  * is currently being used in a text widget.  These structures are kept
  93.  * in textPtr->tagTable and referred to in other structures, like
  94.  * TkTagToggles.
  95.  */
  96.  
  97. typedef struct TkTextTag {
  98.     char *name;            /* Name of this tag.  This field is actually
  99.                  * a pointer to the key from the entry in
  100.                  * textPtr->tagTable, so it needn't be freed
  101.                  * explicitly. */
  102.     int priority;        /* Priority of this tag within widget.  0
  103.                  * means lowest priority.  Exactly one tag
  104.                  * has each integer value between 0 and
  105.                  * numTags-1. */
  106.  
  107.     /*
  108.      * Information for displaying text with this tag.  The information
  109.      * belows acts as an override on information specified by lower-priority
  110.      * tags.  If no value is specified, then the next-lower-priority tag
  111.      * on the text determins the value.  The text widget itself provides
  112.      * defaults if no tag specifies an override.
  113.      */
  114.  
  115.     Tk_3DBorder border;        /* Used for drawing background.  NULL means
  116.                  * no value specified here. */
  117.     int borderWidth;        /* Width of 3-D border for background. */
  118.     int relief;            /* 3-D relief for background. */
  119.     Pixmap bgStipple;        /* Stipple bitmap for background.  None
  120.                  * means no value specified here. */
  121.     XColor *fgColor;        /* Foreground color for text.  NULL means
  122.                  * no value specified here. */
  123.     XFontStruct *fontPtr;    /* Font for displaying text.  NULL means
  124.                  * no value specified here. */
  125.     Pixmap fgStipple;        /* Stipple bitmap for text and other
  126.                  * foreground stuff.   None means no value
  127.                  * specified here.*/
  128.     int underline;        /* Non-zero means draw underline underneath
  129.                  * text. */
  130. } TkTextTag;
  131.  
  132. /*
  133.  * The macro below determines whether or not a particular tag affects
  134.  * the way information is displayed on the screen.  It's used, for
  135.  * example, to determine when to redisplay in response to tag changes.
  136.  */
  137.  
  138. #define TK_TAG_AFFECTS_DISPLAY(tagPtr)                     \
  139.     (((tagPtr)->border != NULL) || ((tagPtr)->bgStipple != None)    \
  140.     || ((tagPtr)->fgColor != NULL) || ((tagPtr)->fontPtr != NULL)     \
  141.     || ((tagPtr)->fgStipple != None) || ((tagPtr)->underline))
  142.  
  143. /*
  144.  * The data structure below is used for searching a B-tree for transitions
  145.  * on a single tag (or for all tag transitions).  No code outside of
  146.  * tkTextBTree.c should ever modify any of the fields in these structures,
  147.  * but it's OK to use them for read-only information.
  148.  */
  149.  
  150. typedef struct TkTextSearch {
  151.     TkTextBTree tree;            /* Tree being searched. */
  152.     int line1, ch1;            /* Position of last tag returned
  153.                      * by TkBTreeNextTag. */
  154.     int line2, ch2;            /* Stop search after all tags at this
  155.                      * character position have been
  156.                      * processed. */
  157.     TkTextTag *tagPtr;            /* Tag to search for (or tag found, if
  158.                      * allTags is non-zero). */
  159.     int allTags;            /* Non-zero means ignore tag check:
  160.                      * search for transitions on all
  161.                      * tags. */
  162.     TkTextLine *linePtr;        /* Line currently being searched.  NULL
  163.                      * means search is over. */
  164.     TkAnnotation *annotPtr;        /* Pointer to next annotation to
  165.                      * consider.  NULL means no annotations
  166.                      * left in current line;  must go on
  167.                      * to next line. */
  168. } TkTextSearch;
  169.  
  170. /*
  171.  * A data structure of the following type is kept for each text widget that
  172.  * currently exists for this process:
  173.  */
  174.  
  175. typedef struct TkText {
  176.     Tk_Window tkwin;        /* Window that embodies the text.  NULL
  177.                  * means that the window has been destroyed
  178.                  * but the data structures haven't yet been
  179.                  * cleaned up.*/
  180.     Tcl_Interp *interp;        /* Interpreter associated with widget.  Used
  181.                  * to delete widget command.  */
  182.     TkTextBTree tree;        /* B-tree representation of text and tags for
  183.                  * widget. */
  184.     Tcl_HashTable tagTable;    /* Hash table that maps from tag names to
  185.                  * pointers to TkTextTag structures. */
  186.     int numTags;        /* Number of tags currently defined for
  187.                  * widget;  needed to keep track of
  188.                  * priorities. */
  189.     Tcl_HashTable markTable;    /* Hash table that maps from mark names to
  190.                  * pointer to TkAnnotation structures of
  191.                  * type TK_ANNOT_MARK. */
  192.     Tk_Uid state;        /* Normal or disabled.  Text is read-only
  193.                  * when disabled. */
  194.  
  195.     /*
  196.      * Default information for displaying (may be overridden by tags
  197.      * applied to ranges of characters).
  198.      */
  199.  
  200.     Tk_3DBorder border;        /* Structure used to draw 3-D border and
  201.                  * default background. */
  202.     int borderWidth;        /* Width of 3-D border to draw around entire
  203.                  * widget. */
  204.     int padX, padY;        /* Padding between text and window border. */
  205.     int relief;            /* 3-d effect for border around entire
  206.                  * widget: TK_RELIEF_RAISED etc. */
  207.     Cursor cursor;        /* Current cursor for window, or None. */
  208.     XColor *fgColor;        /* Default foreground color for text. */
  209.     XFontStruct *fontPtr;    /* Default font for displaying text. */
  210.  
  211.     /*
  212.      * Additional information used for displaying:
  213.      */
  214.  
  215.     Tk_Uid wrapMode;        /* How to handle wrap-around.  Must be
  216.                  * tkTextCharUid, tkTextNoneUid, or
  217.                  * tkTextWordUid. */
  218.     int width, height;        /* Desired dimensions for window, measured
  219.                  * in characters. */
  220.     int setGrid;        /* Non-zero means pass gridding information
  221.                  * to window manager. */
  222.     int prevWidth, prevHeight;    /* Last known dimensions of window;  used to
  223.                  * detect changes in size. */
  224.     TkTextLine *topLinePtr;    /* Text line that is supposed to be displayed
  225.                  * at top of the window:  set only by
  226.                  * tkTextDisp.c. */
  227.     struct DInfo *dInfoPtr;    /* Additional information maintained by
  228.                  * tkTextDisp.c. */
  229.     /*
  230.      * Information related to selection.
  231.      */
  232.  
  233.     TkTextTag *selTagPtr;    /* Pointer to "sel" tag.  Used to tell when
  234.                  * a new selection has been made. */
  235.     Tk_3DBorder selBorder;    /* Border and background for selected
  236.                  * characters.  This is a copy of information
  237.                  * in *cursorTagPtr, so it shouldn't be
  238.                  * explicitly freed. */
  239.     int selBorderWidth;        /* Width of border around selection. */
  240.     XColor *selFgColorPtr;    /* Foreground color for selected text.
  241.                  * This is a copy of information in
  242.                  * *cursorTagPtr, so it shouldn't be
  243.                  * explicitly freed. */
  244.     int exportSelection;    /* Non-zero means tie "sel" tag to X
  245.                  * selection. */
  246.     int selLine, selCh;        /* Used during multi-pass selection retrievals.
  247.                  * These identify the next character to be
  248.                  * returned from the selection. */
  249.     int selOffset;        /* Offset in selection corresponding to
  250.                  * selLine and selCh.  -1 means neither
  251.                  * this information nor selLine or selCh
  252.                  * is of any use. */
  253.  
  254.     /*
  255.      * Information related to insertion cursor:
  256.      */
  257.  
  258.     TkAnnotation *insertAnnotPtr;
  259.                 /* Always points to annotation for "insert"
  260.                  * mark. */
  261.     Tk_3DBorder insertBorder;    /* Used to draw vertical bar for insertion
  262.                  * cursor. */
  263.     int insertWidth;        /* Total width of insert cursor. */
  264.     int insertBorderWidth;    /* Width of 3-D border around insert cursor. */
  265.     int insertOnTime;        /* Number of milliseconds cursor should spend
  266.                  * in "on" state for each blink. */
  267.     int insertOffTime;        /* Number of milliseconds cursor should spend
  268.                  * in "off" state for each blink. */
  269.     Tk_TimerToken insertBlinkHandler;
  270.                 /* Timer handler used to blink cursor on and
  271.                  * off. */
  272.  
  273.     /*
  274.      * Information used for event bindings associated with tags:
  275.      */
  276.  
  277.     Tk_BindingTable bindingTable;
  278.                 /* Table of all bindings currently defined
  279.                  * for this widget.  NULL means that no
  280.                  * bindings exist, so the table hasn't been
  281.                  * created.  Each "object" used for this
  282.                  * table is the address of a tag. */
  283.     TkAnnotation *currentAnnotPtr;
  284.                 /* Pointer to annotation for "current" mark,
  285.                  * or NULL if none. */
  286.     XEvent pickEvent;        /* The event from which the current character
  287.                  * was chosen.  Must be saved so that we
  288.                  * can repick after insertions and deletions. */
  289.  
  290.     /*
  291.      * Miscellaneous additional information:
  292.      */
  293.  
  294.     char *yScrollCmd;        /* Prefix of command to issue to update
  295.                  * vertical scrollbar when view changes. */
  296.     int scanMarkLine;        /* Line that was at the top of the window
  297.                  * when the scan started. */
  298.     int scanMarkY;        /* Y-position of mouse at time scan started. */
  299.     int flags;            /* Miscellaneous flags;  see below for
  300.                  * definitions. */
  301. } TkText;
  302.  
  303. /*
  304.  * Flag values for TkText records:
  305.  *
  306.  * GOT_SELECTION:        Non-zero means we've already claimed the
  307.  *                selection.
  308.  * INSERT_ON:            Non-zero means insertion cursor should be
  309.  *                displayed on screen.
  310.  * GOT_FOCUS:            Non-zero means this window has the input
  311.  *                focus.
  312.  * BUTTON_DOWN:            1 means that a mouse button is currently
  313.  *                down;  this is used to implement grabs
  314.  *                for the duration of button presses.
  315.  * IN_CURRENT:            1 means that an EnterNotify event has been
  316.  *                delivered to the current character with
  317.  *                no matching LeaveNotify event yet.
  318.  */
  319.  
  320. #define GOT_SELECTION    1
  321. #define INSERT_ON    2
  322. #define GOT_FOCUS    4
  323. #define BUTTON_DOWN    8
  324. #define IN_CURRENT    0x10
  325.  
  326. /*
  327.  * The constant below is used to specify a line when what is really
  328.  * wanted is the entire text.  For now, just use a very big number.
  329.  */
  330.  
  331. #define TK_END_OF_TEXT 1000000
  332.  
  333. /*
  334.  * Declarations for variables shared among the text-related files:
  335.  */
  336.  
  337. extern int tkBTreeDebug;
  338. extern Tk_Uid tkTextCharUid;
  339. extern Tk_Uid tkTextDisabledUid;
  340. extern Tk_Uid tkTextNoneUid;
  341. extern Tk_Uid tkTextNormalUid;
  342. extern Tk_Uid tkTextWordUid;
  343.  
  344. /*
  345.  * Declarations for procedures that are used by the text-related files
  346.  * but shouldn't be used anywhere else in Tk (or by Tk clients):
  347.  */
  348.  
  349. extern void        TkBTreeAddAnnotation _ANSI_ARGS_((
  350.                 TkAnnotation *annotPtr));
  351. extern int        TkBTreeCharTagged _ANSI_ARGS_((TkTextLine *linePtr,
  352.                 int index, TkTextTag *tagPtr));
  353. extern void        TkBTreeCheck _ANSI_ARGS_((TkTextBTree tree));
  354. extern TkTextBTree    TkBTreeCreate _ANSI_ARGS_((void));
  355. extern void        TkBTreeDestroy _ANSI_ARGS_((TkTextBTree tree));
  356. extern void        TkBTreeDeleteChars _ANSI_ARGS_((TkTextBTree tree,
  357.                 TkTextLine *line1Ptr, int ch1,
  358.                 TkTextLine *line2Ptr, int ch2));
  359. extern TkTextLine *    TkBTreeFindLine _ANSI_ARGS_((TkTextBTree tree,
  360.                 int line));
  361. extern TkTextTag **    TkBTreeGetTags _ANSI_ARGS_((TkTextBTree tree,
  362.                 TkTextLine *linePtr, int ch, int *numTagsPtr));
  363. extern void        TkBTreeInsertChars _ANSI_ARGS_((TkTextBTree tree,
  364.                 TkTextLine *linePtr, int ch, char *string));
  365. extern int        TkBTreeLineIndex _ANSI_ARGS_((TkTextLine *linePtr));
  366. extern TkTextLine *    TkBTreeNextLine _ANSI_ARGS_((TkTextLine *linePtr));
  367. extern int        TkBTreeNextTag _ANSI_ARGS_((TkTextSearch *searchPtr));
  368. extern int        TkBTreeNumLines _ANSI_ARGS_((TkTextBTree tree));
  369. extern void        TkBTreeRemoveAnnotation _ANSI_ARGS_((
  370.                 TkAnnotation *annotPtr));
  371. extern void        TkBTreeStartSearch _ANSI_ARGS_((TkTextBTree tree,
  372.                 int line1, int ch1, int line2, int ch2,
  373.                 TkTextTag *tagPtr, TkTextSearch *searchPtr));
  374. extern void        TkBTreeTag _ANSI_ARGS_((TkTextBTree tree, int line1,
  375.                 int ch1, int line2, int ch2, TkTextTag *tagPtr,
  376.                 int add));
  377. extern void        TkTextBindProc _ANSI_ARGS_((ClientData clientData,
  378.                 XEvent *eventPtr));
  379. extern TkTextLine *    TkTextCharAtLoc _ANSI_ARGS_((TkText *textPtr,
  380.                 int x, int y, int *chPtr));
  381. extern void        TkTextCreateDInfo _ANSI_ARGS_((TkText *textPtr));
  382. extern TkTextTag *    TkTextCreateTag _ANSI_ARGS_((TkText *textPtr,
  383.                 char *tagName));
  384. extern void        TkTextFreeDInfo _ANSI_ARGS_((TkText *textPtr));
  385. extern void        TkTextFreeTag _ANSI_ARGS_((TkTextTag *tagPtr));
  386. extern int        TkTextGetIndex _ANSI_ARGS_((Tcl_Interp *interp,
  387.                 TkText *textPtr, char *string, int *lineIndexPtr,
  388.                 int *chPtr));
  389. extern void        TkTextLinesChanged _ANSI_ARGS_((TkText *textPtr,
  390.                 int first, int last));
  391. extern void        TkTextLostSelection _ANSI_ARGS_((
  392.                 ClientData clientData));
  393. extern void        TkTextPickCurrent _ANSI_ARGS_((TkText *textPtr,
  394.                 XEvent *eventPtr));
  395. extern void        TkTextPrintIndex _ANSI_ARGS_((int line, int ch,
  396.                 char *string));
  397. extern TkTextLine *    TkTextRoundIndex _ANSI_ARGS_((TkText *textPtr,
  398.                 int *lineIndexPtr, int *chPtr));
  399. extern void        TkTextRedrawRegion _ANSI_ARGS_((TkText *textPtr,
  400.                 int x, int y, int width, int height));
  401. extern void        TkTextRedrawTag _ANSI_ARGS_((TkText *textPtr,
  402.                 int line1, int ch1, int line2, int ch2,
  403.                 TkTextTag *tagPtr, int withTag));
  404. extern void        TkTextRelayoutWindow _ANSI_ARGS_((TkText *textPtr));
  405. extern TkAnnotation *    TkTextSetMark _ANSI_ARGS_((TkText *textPtr, char *name,
  406.                 int line, int ch));
  407. extern void        TkTextSetView _ANSI_ARGS_((TkText *textPtr,
  408.                 int line, int pickPlace));
  409. extern int        TkTextTagCmd _ANSI_ARGS_((TkText *textPtr,
  410.                 Tcl_Interp *interp, int argc, char **argv));
  411. extern void        TkTextUnpickCurrent _ANSI_ARGS_((TkText *textPtr));
  412.  
  413. #endif /* _TKTEXT */
  414.